import os
import shutil
from PyPDF2 import PdfFileReader, PdfFileWriter
from PyPDF2 import PdfReader, PdfWriter
from reportlab.pdfgen import canvas
import io

# 文件夹路径
folder_path = "./image_paths/pdf_files/merged_pdf"
new_folder_path = "./image_paths/pdf_files/new_merged_pdf"

# 判断新文件夹是否存在，如果不存在则创建
if not os.path.exists(new_folder_path):
    os.makedirs(new_folder_path)
else:
    print(f"P{new_folder_path}文件夹已存在")
# 获取文件夹中的所有文件
file_list = os.listdir(folder_path)

# 遍历文件列表
for file_name in file_list:
    if file_name.endswith(".pdf"):  # 筛选出以 .pdf 结尾的文件
        file_path = os.path.join(folder_path, file_name)  # 构建完整的文件路径
        # 构建新的文件路径
        new_file_path = os.path.join(new_folder_path, file_name)
        # 复制文件
        shutil.copy(file_path, new_file_path)
        print("已复制文件:", file_path, "到", new_file_path)

